package com.ruoyi.caipiao.utils;

import cn.hutool.core.date.DateUtil;
import org.junit.Test;

import java.io.File;
import java.util.*;

/**
 * @author wangcen
 * @date 2025/1/23 17:24
 */

public class Pl5Test {

    static String zjhm = "36614";

    @Test
    public void getPc() {
        String yyyyMMdd = "20250218";
        String dir = "D:\\pl5\\" + yyyyMMdd;
        Set<String> jj = new TreeSet<>();
        File[] files = new File(dir).listFiles();

        int cc = 0;

        if (files != null) {
            for (int i = 0; i < files.length; i++) {
                int ctt = new Random().nextInt(4)+2;

                List<String> s1 = MyFileUtil.readFileAsList(files[i]);
                Set<String> set1 = new TreeSet<>();
                for (String s : s1) {
                    int ct = Integer.parseInt(s.substring(s.indexOf(">") + 1));
                    if (ct >=ctt) {
                        set1.add(s.substring(0, 5));
                    }
                }
                System.out.println(i + "--"+files[i].getName()+ "---->set1Size:" + set1.size() + ", jz:" + set1.contains(zjhm));

                jj.addAll(set1);

//                if (jj.size() >= 10000) {
//
////                    Set<String> fj = Pl5NumUtil.getFj(jj);
//
//                    System.out.println(i + "---->fjSize:" + jj.size() + ", jz:" + jj.contains(zjhm));
//                    MyFileUtil.writeContentToFile(dir + "\\排除.txt", jj.toString() + "\n", true);
//                    jj.clear();
//                    if (cc >= 10) {
//                        break;
//                    }
//                }
            }
        }

        System.out.println(jj.size());
    }

    @Test
    public void cal() {

//        Set<String> sets = MyFileUtil.readFileToSet(new File("D:\\pl5\\20250210\\排除.txt"));
        Set<String> sets = MyFileUtil.readFileToSet(new File("D:\\pl5\\20250215\\排除.txt"));
        System.out.println(sets.size() + ",zj:" + sets.contains(zjhm));
        int j = 0;
        for (int i = 0; i < 10000; i++) {
            String num = Pl5NumUtil.getNum();
            if (!sets.contains(num)) {
                System.out.println(num);
                j++;
                if (j == 4) {
                    break;
                }
            }
        }

    }

    @Test
    public void generateCode() {
        for (int i = 0; i < 1000; i++) {
            cal(i);
        }
    }

    public void cal(int index) {

        String yyyyMMdd = DateUtil.format(new Date(), "yyyyMMdd");
        String dir = "D:\\pl5\\" + yyyyMMdd + "\\";
        File file = new File(dir);
        if (!file.exists()) {
            file.mkdirs();
        }
        Map<String, Integer> numsMap = new HashMap<>();
        for (int i = 0; i < 30000; i++) {
            String num = Pl5NumUtil.getNum();
            numsMap.merge(num, 1, Integer::sum);
        }
        StringBuilder ss = new StringBuilder();
        int k = 1;
        for (Map.Entry<String, Integer> entry : numsMap.entrySet()) {
            String num = entry.getKey();
            Integer ct = entry.getValue();
            ss.append(num).append("->").append(ct).append("\n");
            if (k % 10000 == 0) {
                MyFileUtil.writeContentToFile(dir + index + "_all_nums.txt", ss.toString(), true);
            }
            k++;
        }
    }
}
